GO
IF OBJECT_ID ( 'createDocFilter', 'P' ) IS NOT NULL 
    DROP PROCEDURE [dbo].[createDocFilter];
GO
CREATE PROCEDURE [dbo].[createDocFilter]
	@DocFilterName VARCHAR(40),
    @DocFilterId INT OUT
AS
BEGIN
    SET NOCOUNT ON;
    INSERT INTO [FILTER] ([NAME], [TABLE_NAME], [TYPE])
		VALUES(@DocFilterName, 'Document', 'System')
	SET @DocFilterId = @@IDENTITY;
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@DocFilterId, 'DocumentId', 'Document', 'Id', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@DocFilterId, 'DocumentName', 'Document', 'Name', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@DocFilterId, 'DocumentDescription', 'Document', 'Description', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@DocFilterId, 'DocumentEntity', 'Document', 'Entity', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@DocFilterId, 'ModulesName', 'Modules', 'Name', 'Text')
	INSERT INTO [FILTER_FIELD]
		([FILTER_ID], [FIELD_NAME], [TABLE_NAME], [COLUMN_NAME], [TYPE])
		VALUES (@DocFilterId, 'ModulesDescription', 'Modules', 'Description', 'Text')
END
GO
